package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.SkuItemsService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.SkuItemsAddVO;
import com.junzhiit.nengji.cms.web.vo.SkuItemsEditVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/sku/items")
public class SkuItemsController extends BaseController {

	@Autowired
	private SkuItemsService skuItemsService;

	@ApiOperation(value = "查询sku_items规格")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp, String skuId) {
		return skuItemsService.findAll(dtp, skuId);
	}

	@ApiOperation(value = "添加sku_items规格")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(SkuItemsAddVO skuItemsAddVO) {
		AssertUtil.notBlank(skuItemsAddVO.getSkuId(), "skuId is required");
		AssertUtil.notBlank(skuItemsAddVO.getStandard(), "standard is required");
		return skuItemsService.add(skuItemsAddVO);
	}

	@ApiOperation(value = "删除sku_items规格")
	@RequestMapping(value = "/delete", method = RequestMethod.PUT)
	public ResultVO delete(String id) {
		return skuItemsService.delete(id);
	}

	@ApiOperation(value = "批量删除sku_items规格")
	@RequestMapping(value = "/batch/delete", method = RequestMethod.PUT)
	public ResultVO batchDelete(String[] ids) {
		return skuItemsService.batchDelete(ids);
	}

	@ApiOperation(value = "修改sku_items规格")
	@RequestMapping(value = "/update", method = RequestMethod.PUT)
	public ResultVO update(SkuItemsEditVO skuItemsEditVO) {
		return skuItemsService.update(skuItemsEditVO);
	}

	@ApiOperation(value="获取所有sku_items")
	@RequestMapping(value="/all",method=RequestMethod.GET)
	public ResultVO getAll(String skuId){
		return skuItemsService.getAll(skuId);
	}
	
	
	@ApiOperation(value="获取商品正在使用该sku_items的总数")
	@RequestMapping(value="/use/count",method=RequestMethod.GET)
	public ResultVO queryGoodsAboutSkuItemsCount(String skuItemsId){
		AssertUtil.notBlank(skuItemsId, "skuItemsId is required");
		return skuItemsService.queryGoodsAboutSkuItemsCount(skuItemsId);
	}
}
